package com.springboot.component.dubbo;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// @Activate 无条件自动激活
@Activate(group = {Constants.PROVIDER, Constants.CONSUMER})
public class DubboLogFilter implements Filter{
	private final Logger LOGGER = LoggerFactory.getLogger(DubboLogFilter.class);

	@Override
	public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
		// TODO Auto-generated method stub
		LOGGER.info("DubboLogFilter开始");
		Result rs = null; 
		try {
			String clientIp = RpcContext.getContext().getAttachment("ip");
			rs = invoker.invoke(invocation);
			System.out.println("远程地址ip"+clientIp);
		}catch (Exception e) {
			// TODO: handle exception
		}
		LOGGER.info("DubboLogFilter结束");

		return rs;
	}

}

